const Router = require("koa-router");

const router = new Router();
const jwt = require("jsonwebtoken");

router.post("/login", (ctx) => {
  let { uname, pwd } = ctx.request.body;

  let privateKey = "hello koa";
  var token = jwt.sign({ uname: uname }, privateKey, { algorithm: "HS256", expiresIn: "10h" });
  ctx.body = {
    msg: "login success",
    token: "Bearer " + token,
  };
});

module.exports = router;
